<?php

$this->menu=array(
	array('label'=>'List PostModel', 'url'=>array('index')),
	array('label'=>'Create PostModel', 'url'=>array('create')),
);

Yii::app()->getClientScript()->registerCoreScript( 'jquery.ui' );
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('post-model-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php
$str_js = "
        var fixHelper = function(e, ui) {
            ui.children().each(function() {
                $(this).width($(this).width());
            });
            return ui;
        };
 
        $('#post-model-grid table.items tbody').sortable({
            forcePlaceholderSize: true,
            forceHelperSize: true,
            items: 'tr',
            update : function () {
                serial = $('#post-model-grid table.items tbody').sortable('serialize', {key: 'items[]', attribute: 'class'});
                $.ajax({
                    'url': '" . $this->createUrl('//admin/sort') . "',
                    'type': 'post',
                    'data': serial,
                    'success': function(data){
                    },
                    'error': function(request, status, error){
                        alert('We are unable to set the sort order at this time.  Please try again in a few minutes.');
                    }
                });
            },
            helper: fixHelper
        }).disableSelection();
    ";
 
    Yii::app()->clientScript->registerScript('sortable-project', $str_js);
    ?>

<h1>Manage Post</h1>

<?php echo CHtml::submitButton('Advanced Search',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('post/_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'post-model-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'id',
		'title',
		'content',
		//'tags',
		'post_status',
		'create_time',
		
		'update_time',
		//'author_id',
             array(
                'name'=>'author_id',   
                'value'=>'MemberModel::model()->findByPk($data->author_id)->email',
                'filter' => CHtml::listData(MemberModel::model()->findAll(),'id','email'),
        ),
		/*'post_name',
		'post_url',
		'post_type',*/
		'post_order',
		
		array(
        'class'=>'CButtonColumn',
        'template'=>'{view}{update}{delete}',
        'viewButtonUrl'=>'Yii::app()->createUrl("/admin/view", array("id" => $data["id"],"model" => "post"))',
        'deleteButtonUrl'=>'Yii::app()->createUrl("/admin/delete", array("id" =>  $data["id"],"model" => "post"))',
        'updateButtonUrl'=>'Yii::app()->createUrl("/admin/update", array("id" =>  $data["id"],"model" => "post"))',
        
    ),
            
	),
)); ?>